//
//  WorkHomeVC.m
//  XLDoctor
//
//  Created by longma on 2018/7/27.
//  Copyright © 2018年 XLH. All rights reserved.
//mj修改名称

#import "PhysicalInfoController.h"
@interface PhysicalInfoController ()
@property (weak, nonatomic) IBOutlet MJUITextField *heightTextField;
@property (weak, nonatomic) IBOutlet MJUITextField *weightTextField;
@property (weak, nonatomic) IBOutlet MJUIBaseButton *confirmButton;
@property (weak, nonatomic) IBOutlet UIView *heightView;
@property (weak, nonatomic) IBOutlet UIView *weightView;
@property (weak, nonatomic) IBOutlet UILabel *cmLabel;
@property (weak, nonatomic) IBOutlet UILabel *kgLabel;
@end

@implementation PhysicalInfoController


- (void)viewDidLoad {
    [super viewDidLoad];
   
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)mj_setUI{
    [super mj_setUI];
    
    self.mj_titleLocalizable = @"Physical Info";
    self.heightTextField.mj_disableThirdPartyKeyboard = true;
    self.heightTextField.text = self.height;
    self.heightTextField.clearButtonMode = UITextFieldViewModeNever;

    self.weightTextField.mj_disableThirdPartyKeyboard = true;
    self.weightTextField.text = self.weight;
    self.weightTextField.clearButtonMode = UITextFieldViewModeNever;

    MJWeakSelf
    RAC(self.confirmButton, mj_enabled) = [RACSignal combineLatest:@[self.heightTextField.rac_textSignal,self.weightTextField.rac_textSignal] reduce:^id _Nullable(NSString * height,NSString * weight){
        
        if(height.length || weight.length){
            return @(true);
        }
        return @(false);
    }];
    
    [[self.heightTextField rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(__kindof UITextField * _Nullable x) {
        NSLog(@"开始编辑");
        [weakSelf.heightView mj_borderColor:UIColor.mj_appColor width:2];
        weakSelf.cmLabel.textColor = UIColor.mj_blackColor;
    }];
    
    [[self.heightTextField rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(__kindof UITextField * _Nullable x) {
        [weakSelf.heightView mj_borderColor:UIColor.clearColor width:2];
        weakSelf.cmLabel.textColor = UIColor.mj_grayColor;
    }];
    
    //
    [[self.weightTextField rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(__kindof UITextField * _Nullable x) {
        NSLog(@"开始编辑");
        [weakSelf.weightView mj_borderColor:UIColor.mj_appColor width:2];
        weakSelf.kgLabel.textColor = UIColor.mj_blackColor;
    }];
    
    [[self.weightTextField rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(__kindof UITextField * _Nullable x) {
        [weakSelf.weightView mj_borderColor:UIColor.clearColor width:2];
        weakSelf.kgLabel.textColor = UIColor.mj_grayColor;
    }];
    
    [self.confirmButton mj_addAction:^(UIButton *button) {
        if(weakSelf.handleTitleBlock){
            weakSelf.handleTitleBlock(self.heightTextField.text,self.weightTextField.text);
        }
        [weakSelf mj_popViewController];
    }];
}

#pragma mark - 方法
- (void)handleBackButtonClick {
    
    if((![self.height isEqualToString:self.heightTextField.text] && self.heightTextField.text.length) || (![self.weight isEqualToString:self.weightTextField.text] && self.weightTextField.text.length)){
        MJWeakSelf
        MJUIAlertViewConfigure *configure = [[MJUIAlertViewConfigure alloc]init];
        configure.confirmButtonColor = UIColor.mj_appColor;
        configure.confirmTitle = MJUILocalizedString(@"Yes");
        configure.cancelTitle = MJUILocalizedString(@"Cancel_qx");
        configure.messageAlignmentCenter = true;
        NSString *messageString = MJUILocalizedString(@"The Information is not saved. Are you sure you want to exit?");
        [MJUIAlertView alertViewWithTitle:MJUILocalizedString(@"Information Not Saved") message:messageString configure:configure confirmBlock:^{
            [weakSelf mj_popViewController];
        } cancelBlock:^{

        }];
    }else{
        [self mj_popViewController];

    }
}
- (void)requestData{
    
}

#pragma mark - 代理

#pragma mark - 懒加载

@end
